package com.example.sharding.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SnowflakeConfig {

    //@Value("${snowflake.datacenter-id:1}")
    private long datacenterId = 1L;

    //@Value("${snowflake.machine-id:1}")
    private long machineId =  1L;

    // 或者使用Hutool的实现
    @Bean
    public Snowflake snowflake() {
        return IdUtil.getSnowflake(machineId, datacenterId);
    }
}
